{include file="public/header" /}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">会员名称</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="text" id="name" name="name" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" value="{$row.name|default=''}" placeholder="">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">会员折扣</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" id="zhekou" name="zhekou" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" value="{$row.zhekou|default='100'}"
                                placeholder="">
                        </div>
                        <div class="layui-form-mid" style="color: #FF5722;">
                            折扣不能超过100，填写95表示95折，80表示8折
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">购买会员价格,单位:元</div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <input type="number" id="money" name="money" required="" lay-verify="required"
                                autocomplete="off" class="layui-input" value="{$row.money|default='100'}"
                                placeholder="">
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">赠送平台优惠券</div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <div class="layui-col-md12">
                            <a class="layui-btn layui-btn-btn layui-btn-sm layui-btn-normal"
                                onclick="addtable2()">添加</a>
                            <table class="layui-table layui-form" id="table2" lay-filter="table2">
                                <thead>
                                    <tr>
                                        <td>
                                            <div class="layui-table-cell">需要达到使用金额(单位:元)</div>
                                        </td>
                                        <td>
                                            <div class="layui-table-cell">抵扣金额(单位:元)</div>
                                        </td>
                                        <td>
                                            <div class="layui-table-cell">有效时长(单位:天)</div>
                                        </td>
                                        <td>
                                            <div class="layui-table-cell">操作</div>
                                        </td>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if !empty($row.coupon)}
                                    {foreach $row.coupon as $k => $v}
                                    <tr>
                                        <td><input required="" lay-verify="required" type="text" id="layui-input"
                                                class="layui-input" name="parpam[{$k}][getmoney]" value="{$v.getmoney}">
                                        </td>
                                        <td><input required="" lay-verify="required" type="text" id="layui-input"
                                                class="layui-input" name="parpam[{$k}][money]" value="{$v.money}">
                                        </td>
                                        <td><input required="" lay-verify="required" type="text" id="layui-input"
                                                class="layui-input" name="parpam[{$k}][days]" value="{$v.days}">
                                        </td>
                                        <td>
                                            <a class="layui-btn layui-btn-danger layui-btn-xs del2">删除</a>
                                        </td>
                                    </tr>
                                    {/foreach}
                                    {/if}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-card layui-form" lay-filter="component-form-element">
                    <div class="layui-card-header">说明
                    </div>
                    <div class="layui-card-body layui-row layui-col-space10">
                        <div class="layui-col-md12">
                            <textarea id="infos"
                                name="contents">{if !empty($row.contents)}{:htmlspecialchars_decode($row.contents)}{/if}</textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <input type="hidden" value="{$row.id|default=''}" name="id">
                    <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
                </div>
            </form>
        </div>
    </div>

    {include file="public/footer" /}
    <script src="/static/leyedit/Layui-KnifeZ/layui.all.js"></script>
    <script src="/static/leyedit/ace/ace.js"></script>
    <script>
        function addtable2() {
            var i = $('#table2 tbody tr').length;
            //你要添加的html
            var html = '<tr>' +
                '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="parpam[' + i + '][getmoney]" value=""></td>' +
                '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="parpam[' + i + '][money]" value=""></td>' +
                '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="parpam[' + i + '][days]" value=""></td>' +
                '<td><a class="layui-btn layui-btn-danger layui-btn-xs del2" >删除</a></td></tr>';
            $(html).appendTo($('#table2 tbody:last'));
            layui.use(['form'], function () {
                $ = layui.jquery;
                var form = layui.form;
                form.render();
            });
        };
        $('body').on('click', '.del2', function () {
            $(this).closest('tr').remove();
        });
    </script>
    <script>
        layui.use(['form', 'layer', 'upload', 'layedit'], function () {
            $ = layui.jquery;
            var form = layui.form
                , upload = layui.upload
                , element = layui.element
                , layer = layui.layer;
            var layedit = layui.layedit;
            layedit.set({
                //暴露layupload参数设置接口 --详细查看layupload参数说明
                uploadImage: {
                    url: '/Base/upload_img',
                    accept: 'image',
                    acceptMime: 'image/*',
                    exts: 'jpg|png|gif|bmp|jpeg',
                    size: '100240'
                }
                //右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
                //传递参数：
                //图片： imgpath --图片路径
                //视频： filepath --视频路径 imgpath --封面路径
                , calldel: {
                    url: '/Base/upload_img'
                }
                //开发者模式 --默认为false
                , devmode: false
                //插入代码设置
                , codeConfig: {
                    hide: true,  //是否显示编码语言选择框
                    default: 'javascript' //hide为true时的默认语言格式
                }

                , tool: [
                    'strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right'
                ]
                , height: '300px'
            });
            var infos = layedit.build('infos');
            form.on('submit(add)', function (data) {
                data.field.contents = layedit.getContent(infos);
                $.ajax({
                    type: 'post',
                    data: data.field,
                    success: function (res) {
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });
        });
    </script>
</body>

</html>